<?php
namespace Menu\Model;
use Think\Model;
class UsersModel extends Model {
	//增加
	public function userAdd(){
		$data = $this->create();
		$data['password'] = md5(md5(I('post.password')));
		if($this->add($data)){
			$msg['info'] = "添加成功";
			$msg['num']  = 1;
		}
		return $msg;
	}
	//删除
	public function userDel($id){
		$where   = array('user_id'=>$id);
		$Resoult = $this
		->where($where)
		->delete();
		if($Resoult){
			$msg['num']  = 1;
			$msg['info'] = "删除成功"; 
		}
		return $msg;
	}
	//登录
	public function userRead(){
		$user_name = I('post.user_name');
		$password  = md5(md5(I('post.password')));
		$where = array('user_name'=>$user_name);
		$find  = $this
		// ->getField('password')
		->where($where)
		->find();
		if($find['password'] == $password){
			$msg['info']      = "登录成功";
			$msg['user_name'] = $user_name;
			$msg['num']       = 1;
		}
		return $msg;
	}

	public function userSel(){
		$count      = $this->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $this->limit($Page->firstRow.','.$Page->listRows)->select();
		$data['list'] = $list;
		$data['page'] = $show;
		return $data;
	}
}